<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

$creator_id = UV::readInt(strip_tags($route->GET("user")));

$query = "select `N`.*,`U`.`login` from `news` as `N`,`users` as `U` where `N`.`user_id` = `U`.`user_id` ";
$query .= ($creator_id ? "and `N`.`user_id` = '$creator_id' " : "");
$query .= "order by `news_id` desc";
$news_list = $db->getTable($query);

$page = UV::readInt(strip_tags($route->GET("page")));
$limit = 10;
$count = count($news_list);
$max_page = ceil($count / $limit);
if ($page < 1)
	$page = 1;
elseif ($page > $max_page)
	$page = $max_page;

$query .= " limit ".($page-1)*$limit.",$limit";
$news_list = $db->getTable($query);

require_once ADMIN.DS."head.php";
?>

<div class="full">
	<div class="submenu_container">
		<a class="submenu_button all_news submenu_button_active" href='/admin/content/list'>Список новостей</a>
		<a class="submenu_button add_news" href='/admin/content/add'>Добавить новость</a>
	</div>
	<h3>Список новостей</h3>
	<?php
		if ($creator_id){
			$creator = $db->getCell("select `login` from `users` where `user_id` = '$creator_id' limit 1");
			echo "<div class='group_container'><div class='filter_button'>$creator <a href='?".$route->getGet("user")."'></a></div></div>";
		}
		foreach ($news_list as $news_item)
		{
			?><div class="moderationrecord">
				<div class="recorddate left"><?php echo date("d.m.Y",$news_item['time'])."<br /><span style='font-size:9pt;color:black'>Приоритет: ".$news_item['order']."</span>"; ?></div>
				<div class="record left">
					<div class="recordtitle"><?php echo "<a target='_blank' href='/news/".$news_item['news_id']."-".translitIt($news_item['title'])."'>".$news_item['title']."</a>"; ?></div>
					<div class="recorduser">добавил: <?php echo "<a href='?".$route->getGet("user")."user=".$news_item['user_id']."'>".$news_item['login']."</a>"; ?></div>
					<div class="recordtext"><?php echo strip_tags($news_item['preview']); ?></div>
				</div>
				<div class="recordbuttons right">
					<a class="moder_buttons redit" href="/admin/content/edit/<?php echo $news_item['news_id']; ?>"></a>
					<a class="moder_buttons rdelete" href="/admin/content/delete/<?php echo $news_item['news_id']; ?>"></a>
				</div>
			</div><?php
		}
		echo showPages($count,$limit);
	?>
</div>

<?php require_once ADMIN.DS."footer.php"; ?>
